// 对axios进行二次封装
import Axios from "axios";
export default function requestApi(url = "", parmas = {}, type = "get") {
    let promise;
    return new Promise((resolve, reject) => {
        // 判断请求数据的方式是get还是post
        if (type.toLowerCase() == "get") {
            let parmasStr = "";
            Object.keys(parmas).forEach(key => {
                parmasStr += key + "=" + parmas[key] + "&";
            })
            if (parmasStr != "") {
                parmasStr = parmasStr.substr(0, parmasStr.lastIndexOf("&"));
            }
            url += "?" + parmasStr
            promise = Axios.get(url);
        } else if (type == "post") {
            promise = Axios.post(url, parmas);
        }
        // 返回结果
        promise.then(response => {
            resolve(response.data);
        }).catch(err => {
            reject(err);
        })
    })
}